package com.graduation.springbootinit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.graduation.springbootinit.model.entity.ActivityPart.ExchangeRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ExchangeRecordMapper extends BaseMapper<ExchangeRecord> {
    
    /**
     * 获取用户兑换记录
     */
    @Select("SELECT * FROM community_activities_exchange_record WHERE user_id = #{userId} ORDER BY created_at DESC")
    Page<ExchangeRecord> selectPageByUserId(Page<ExchangeRecord> page, @Param("userId") Long userId);
    
    /**
     * 更新记录状态
     */
    @Update("UPDATE community_activities_exchange_record SET status = #{status} WHERE id = #{id}")
    int updateStatus(@Param("id") Long id, @Param("status") Integer status);
    
    /**
     * 获取待发货记录
     */
    @Select("SELECT * FROM community_activities_exchange_record WHERE status = 0 ORDER BY created_at ASC")
    Page<ExchangeRecord> selectPendingRecords(Page<ExchangeRecord> page);
} 